package com.jatec.webcopy;

import java.util.ArrayList;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class WebItemDB extends SQLiteOpenHelper {

	public static final String DATABASE_NAME = "webitems";
    private static final int DATABASE_VERSION = 2;
    private static final String WEBITEMS_TABLE_NAME = "webitems";
    private static final String WEBITEMS_TABLE_CREATE =
                "CREATE TABLE " + WEBITEMS_TABLE_NAME + " (" +
                "name TEXT, " +
                "url TEXT, " +
                "linkDepth INT, " +
                "localPath TEXT);";
    
    private ArrayList<WebItem> data = new ArrayList<WebItem>();

    WebItemDB(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
        
        loadDummy();
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL(WEBITEMS_TABLE_CREATE);
    }

	@Override
	public void onUpgrade(SQLiteDatabase arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub
		
	}
	
	public void store(WebItem item){
		data.add(item);
	}

	public WebItem[] readAll(){
		WebItem[] array = new WebItem[data.size()];
		
		return data.toArray(array);
	}
    
	
	private void loadDummy(){
		
		WebItem item = new WebItem();
		item.setName("google");
		item.setUrl("http://www.google.ch");
		item.setLinkDepth(1);
		item.setLocalPath("/mnt/SDCARD");
		data.add(item);
		
		item = new WebItem();
		item.setName("yahoo");
		item.setUrl("http://www.yahoo.com");
		item.setLinkDepth(1);
		item.setLocalPath("/mnt/SDCARD");
		data.add(item);
		
	}
}